package cn.iocoder.yudao.module.wms.dal.mysql.bom;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.wms.controller.admin.bom.vo.BomPageReqVO;
import cn.iocoder.yudao.module.wms.controller.admin.bom.vo.BomRespVO;
import cn.iocoder.yudao.module.wms.dal.dataobject.bom.BomDO;
import cn.iocoder.yudao.module.wms.dal.dataobject.inventory.InventoryDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;

/**
 * BOM主 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface BomMapper extends BaseMapperX<BomDO> {

    default PageResult<BomDO> selectPage(BomPageReqVO reqVO, Collection<String> creator) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BomDO>()
                .eqIfPresent(BomDO::getVersion, reqVO.getVersion())
                .inIfPresent(BomDO::getCreator, creator)
                .betweenIfPresent(BomDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BomDO::getId));
    }

    default PageResult<BomRespVO> selectJoinPage(BomPageReqVO reqVO, Collection<String> creator) {
        return selectJoinPage(reqVO, BomRespVO.class , new MPJLambdaWrapperX<BomDO>()
                .selectAll(BomDO.class)
                .likeIfPresent(BomDO::getVersion, reqVO.getVersion())
                .inIfPresent(BomDO::getCreator, creator)
                .betweenIfPresent(BomDO::getCreateTime, reqVO.getCreateTime())
                .select(InventoryDO::getCode, InventoryDO::getName)
                .leftJoin(InventoryDO.class, InventoryDO::getId, BomDO::getInventoryId)
                .like(InventoryDO::getCode, reqVO.getCode())
                .like(InventoryDO::getName, reqVO.getName())
                .orderByDesc(BomDO::getId));
    }

}